package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TExamPackage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPackageCategory;
import com.ruoyi.system.service.ITPackageCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐类型分类Controller
 * 
 * @author ruoyi
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/system/category")
public class TPackageCategoryController extends BaseController
{
    @Autowired
    private ITPackageCategoryService tPackageCategoryService;
    @Autowired
    private TExamPackageController tExamPackageController;

    /**
     * 查询套餐类型分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPackageCategory tPackageCategory)
    {
        startPage();
        List<TPackageCategory> list = tPackageCategoryService.selectTPackageCategoryList(tPackageCategory);
        return getDataTable(list);
    }

    /**
     * 导出套餐类型分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "套餐类型分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPackageCategory tPackageCategory)
    {
        List<TPackageCategory> list = tPackageCategoryService.selectTPackageCategoryList(tPackageCategory);
        ExcelUtil<TPackageCategory> util = new ExcelUtil<TPackageCategory>(TPackageCategory.class);
        util.exportExcel(response, list, "套餐类型分类数据");
    }

    /**
     * 获取套餐类型分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPackageCategoryService.selectTPackageCategoryById(id));
    }

    /**
     * 新增套餐类型分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "套餐类型分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPackageCategory tPackageCategory)
    {
        return toAjax(tPackageCategoryService.insertTPackageCategory(tPackageCategory));
    }

    /**
     * 修改套餐类型分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "套餐类型分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPackageCategory tPackageCategory)
    {
        return toAjax(tPackageCategoryService.updateTPackageCategory(tPackageCategory));
    }

    /**
     * 删除套餐类型分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "套餐类型分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPackageCategoryService.deleteTPackageCategoryByIds(ids));
    }
    @RequestMapping("/getpackagebyname")
    public List<String> getpackagebyname(@RequestParam String name)
    {
    	return tPackageCategoryService.getpackagebyname(name);
    }
    @RequestMapping("/getallpackage")
    public List<TExamPackage> getallpackage()
        {
    	return tPackageCategoryService.getallpackage();
        }
}
